<!DOCTYPE html>
<html>

<head>
    <title>Preview Display</title>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="custom/images/favicon.ico?v=2" />
    <style>
        html,
        body {
            padding: 0px;
            margin: 0px;
        }
    </style>
    <script src='../libs/core/IZrowIfUVaXF.js'></script>
    <script src='../libs/core/VT3MIEkV8AKv.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/core/buckle.js'></script>
    <script src='../libs/core/ht-ui.js'></script>

    <script src='../libs/plugin/ht-edgetype.js'></script>
    <script src="../libs/plugin/ht-obj.js"></script>
    <script src='../libs/plugin/ht-form.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src='../libs/plugin/ht-animation.js'></script>

    <script src='../configs/htconfig.js'></script>

    <!-- <script src="../libs/china.js"></script> -->
    <script src="../libs/echarts.min.js"></script>
    <script src='../libs/echarts.js'></script>
    <script src='../libs/jquery-3.4.1.min.js'></script>
    <script src='../libs/echarts.js'></script>
    <script src='../libs/buckle.js'></script>
    <script src='../libs/knU3sXefAa5Q.js'></script>
	
	<!--<script src='../../requestConfig/config.js'></script> -->
	<script src="../configs/urlConfig.js"></script>

    <script>
		
		var array = window.location.href.split("&")[window.location.href.split("&").length-1].split("=");
		var httpArray = window.location.href.split("&");
		var httpIndex = httpArray.length - 1;
		var paramArray = httpArray[httpIndex].split("=");
		var plantUnit = paramArray[1]; //获取plantUnit
		var startDate;
		var endDate;
		var areaId;
		var stationId;
		
            function init() {
                dataModel = new ht.DataModel();
                graphView = new ht.graph.GraphView(dataModel);
                graphView.addToDOM();
                graphView.deserialize('displays/冀北/场站/机组.json', function(json, dm, gv, datas) {
                    if(json.title) document.title = json.title;
                    if (json.a['json.background']) {
                        var bgJSON = json.a['json.background'];
                        if (bgJSON.indexOf('displays') === 0) {
                            var bgGv = new ht.graph.GraphView();
                            bgGv.deserialize(bgJSON);
                            bgGv.addToDOM();
                            graphView.addToDOM(bgGv.getView());
                        }
                        else if (bgJSON.indexOf('scenes') === 0) {
                            var bgG3d = new ht.graph3d.Graph3dView();
                            bgG3d.deserialize(bgJSON);
                            bgG3d.addToDOM();
                            graphView.addToDOM(bgG3d.getView());
                        }
                        graphView.handleScroll = function() {};
                    }
                    var a = dataModel.getDataByTag("radio");
					 
					
					dataModel.getDataByTag('search').s('select.width',0);
					dataModel.getDataByTag('损失电量').s('select.width',0);
					dataModel.getDataByTag('损失时长').s('select.width',0);
					//dataModel.getDataByTag('日').s('select.width',0);
					//dataModel.getDataByTag('月').s('select.width',0);
					//dataModel.getDataByTag('年').s('select.width',0);
					
					
					
					// 各时间选择器设置默认值
					// 获取当前时间时间戳（毫秒）
					var currentTime = Date.now();
					//将当前时间转换成时间格式
					var currentDate = new Date(parseInt(currentTime));
					var yy = currentDate.getFullYear();      //年
					var mm = currentDate.getMonth() + 1;     //月
					var dd = currentDate.getDate();          //日

					var endDate = yy + "-";
					if(mm < 10) endDate += "0";
					endDate += mm + "-";
					if(dd < 10) endDate += "0";
					endDate += dd;
					
					dm.getDataByTag('endDate').a('ht.value', endDate);
					
					//开始时间与结束时间相隔1天，转换成毫秒
					var offsetTime = 1000 * 3600 * 24 * 60 ;
					//将结束时间减去相隔时间即为开始时间
					var startTime = currentTime - offsetTime;
					startTime = new Date(parseInt(1577808000000));
					var yy = startTime.getFullYear();      //年
					var mm = startTime.getMonth() + 1;     //月
					var dd = startTime.getDate();          //日

					var startDate = yy + "-";
					if(mm < 10) startDate += "0";
					startDate += mm + "-";
					if(dd < 10) startDate += "0";
					startDate += dd;
					
					dm.getDataByTag('startDate').a('ht.value', startDate);
					
					
					var startDate = dm.getDataByTag('startDate').a('ht.value');
					var endDate = dm.getDataByTag('endDate').a('ht.value');
					
					getAreaAndStationIdByUnitId(plantUnit);
					
					getAreaIdAndName();//获取区域名称和对应ID
					getSixValue(plantUnit,startDate,endDate);//六项指标
					
					getBreakdownTop5(plantUnit,startDate,endDate);//故障TOP5
					getBreakdownAnalyse(plantUnit,startDate,endDate);//故障分析
					getBreakdownList(plantUnit,startDate,endDate);//故障查询
					getUnitLostElect(plantUnit,startDate,endDate);//损失电量
					//getUnitLostTime(plantUnit,startDate,endDate);//损失时长  只在切换标签时调用
					getUnitStatusAnalyze(plantUnit,startDate,endDate);//机组状态分析
					
				
					
                });
            }
			
			//根据传入plantUnit获取区域场站，默认显示
			function getAreaAndStationIdByUnitId(plantUnit) {
				$.ajax({
					url: attributeConfig.url + "/epplatform/areaStateTrack/getAreaAndStationIdByUnitId?unitId=" + plantUnit,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data:JSON.stringify(),
					success:function(result){
						if(result.data){
							areaId = result.data.areaId;
							stationId = result.data.stationId;
							var unitId = result.data.unitId;
							getStationIdAndNameInArea(areaId);
							getFanIdAndNameInStation(stationId);
							
							dataModel.getDataByTag('AreaIdAndName').a('ht.value',areaId);
							dataModel.getDataByTag('StationIdAndName').a('ht.value',stationId);
							dataModel.getDataByTag('FanIdAndName').a('ht.value',unitId);
						}
					}
				});
			}
			
			//获取区域名称和对应ID
			function getAreaIdAndName() {
				$.ajax({
					url: attributeConfig.url + "/epplatform/areaStateTrack/getAreaIdAndName",
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data:JSON.stringify(),
					success:function(result){
						let array = [];
						if(result.data){
							result.data.map(((item, index)=> 
								{ array.push(Object.assign({},{label:item.areaName,value:item.id})) }))
							dataModel.getDataByTag('AreaIdAndName').a('ht.dataSource',array);
						}
					}
				});
			}
			
			//获取区域下场站id和名称
			function getStationIdAndNameInArea(areaId) {
				$.ajax({
					url: attributeConfig.url + "/epplatform/areaStateTrack/getStationIdAndNameInArea"+"?areaId="+areaId,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data:JSON.stringify(),
					success:function(result){
						if(result.data){
						let array = [];
							result.data.map(((item, index)=> 
								{ array.push(Object.assign({},{label:item.stationName,value:item.id})) }))
							dataModel.getDataByTag('StationIdAndName').a('ht.dataSource',array);
						}
					}
				});
			}
			//获取场站下机组id和名称
			function getFanIdAndNameInStation(stationId) {
				$.ajax({
					url: attributeConfig.url + "/epplatform/areaStateTrack/getFanIdAndNameInStation"+"?stationId="+stationId,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data:JSON.stringify(),
					success:function(result){
						if(result.data){
						let array = [];
							result.data.map(((item, index)=> 
								{ array.push(Object.assign({},{label:item.fanName,value:item.id})) }))
							dataModel.getDataByTag('FanIdAndName').a('ht.dataSource',array);
						}
					}
				});
			}
			//获取平均可利用率、无故障运行时间等六项指标
			function getSixValue(id,start,end){
				let url = attributeConfig.url + "/epplatform/areaStateTrack/sixValue?plantUnit=" + id + "&"
			
				if(start){
					url = url + "startTime=" + start + "&";
				}
				if(end){
					url = url + "endTime=" + end + "&";
				}
				
				$.ajax({
					url: url,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data:JSON.stringify(),
					success:function(result){
						if(result.data){
							dataModel.getDataByTag('indicators_1').a('data',result.data[0]);
							dataModel.getDataByTag('indicators_2').a('data',result.data[1]);
							dataModel.getDataByTag('indicators_3').a('data',result.data[2]);
							dataModel.getDataByTag('indicators_4').a('data',result.data[3]);
							dataModel.getDataByTag('indicators_5').a('data',result.data[4]);
							dataModel.getDataByTag('indicators_6').a('data',result.data[5]);
						}
					}
				});
			}
			//故障TOP5
			function getBreakdownTop5(id,start,end){
				let url = attributeConfig.url + "/epplatform/areaStateTrack/breakdownTop5?plantUnit=" + id + "&"
			
				if(start){
					url = url + "startTime=" + start + "&";
				}
				if(end){
					url = url + "endTime=" + end + "&";
				}
				$.ajax({
					url: url,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(),
					success:function(result){
						if(result.data){
							dataModel.getDataByTag('bar_breakdownTop').a('xAxisData',result.data.xData);
							dataModel.getDataByTag('bar_breakdownTop').a('barData',result.data.yData);
						}
					}
				});
			}
			//故障分析
			function getBreakdownAnalyse(id,start,end){
				let url = attributeConfig.url + "/epplatform/areaStateTrack/breakdownAnalyse?plantUnit=" + id + "&"
			
				if(start){
					url = url + "startTime=" + start + "&";
				}
				if(end){
					url = url + "endTime=" + end + "&";
				}
				$.ajax({
					url: url,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(),
					success:function(result){
						if(result.data){
							dataModel.getDataByTag('line_breakdownAnalyse').a('xData',result.data.xData);
							dataModel.getDataByTag('line_breakdownAnalyse').a('barData',result.data.yData2);
							dataModel.getDataByTag('line_breakdownAnalyse').a('lineData1',result.data.yData1);
						}
					}
				});
			}
			//故障查询
			function getBreakdownList(id,start,end){
				let url = attributeConfig.url + "/epplatform/areaStateTrack/breakdownList?plantUnit=" + id + "&"
			
				if(start){
					url = url + "startTime=" + start + "&";
				}
				if(end){
					url = url + "endTime=" + end + "&";
				}
				$.ajax({
					url: url,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(),
					success:function(result){
						if(result.data){
							dataModel.getDataByTag('table_breakdown').a('ht.dataSource',result.data);
							dataModel.getDataByTag('暂无数据').s('2d.visible',false);
						}else{
							dataModel.getDataByTag('暂无数据').s('2d.visible',true);
						}
					}
				});
			}
			//导出故障数据
			function breakdownListExport(id,start,end){
				let url = attributeConfig.url + "/epplatform/areaStateTrack/breakdownListExport?plantUnit=" + id + "&"
			
				if(start){
					url = url + "startTime=" + start + "&";
				}
				if(end){
					url = url + "endTime=" + end + "&";
				}
				window.location.href = url;
			}
			
			//损失电量分析
			function getUnitLostElect(id,start,end){
				let param = {
						  "unitId": id ,
						  "startTime": start ,
						  "endTime": end 
						}
				$.ajax({
					url: attributeConfig.url + "/epplatform/v1/electricityAnalysis/unitLostElect",
					type:"POST",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(param),
					success:function(result){
						if(result.data){
							dataModel.getDataByTag('pieData').a('data',result.data);
							dataModel.getDataByTag('pieData').a('legendData',result.data);
						}
					}
				});
			}
			//损失时长
			function getUnitLostTime(id,start,end){
				let param = {
						  "unitId": id ,
						  "startTime": start ,
						  "endTime": end 
						}
				$.ajax({
					url: attributeConfig.url + "/epplatform/v1/electricityAnalysis/unitLostTime",
					type:"POST",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(param),
					success:function(result){
						if(result.data){
							dataModel.getDataByTag('pieData').a('data',result.data);
							dataModel.getDataByTag('pieData').a('legendData',result.data);
						}
					}
				});
			}
			//机组状态分析
			function getUnitStatusAnalyze(unitId,start,end){
				var startTime;
				var endTime;
				if(start){
					startTime = start + " 00:00:00"
				}
				if(end){
					endTime = end + " 23:59:59"
				}
				 
				let param = {
							  "areaId": "" ,
							  "stationId": "" ,
							  "unitId": unitId ,
							  "startTime": startTime,
							  "endTime": endTime
							}
				$.ajax({
					url: attributeConfig.url + "/epplatform/v1/regionSituationTrack/unitStatusAnalyze",
					type:"POST",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(param),
					success:function(result){
						if(result.data){
							if(result.data.data1){
								dataModel.getDataByTag('radar_unitStatus').a('indicator',result.data.data1);
							}
							if(result.data.data2){
								dataModel.getDataByTag('radar_unitStatus').a('raderValue',result.data.data2);
							}
							if(result.data.data3){
								dataModel.getDataByTag('机组状态分析').a('generationCapacity',result.data.data3[0]+' %');
								dataModel.getDataByTag('机组状态分析').a('level',result.data.data3[1]);
								dataModel.getDataByTag('机组状态分析').a('generationTime',result.data.data3[2]+' h');
								dataModel.getDataByTag('机组状态分析').a('MTBF',result.data.data3[3]+' h');
								dataModel.getDataByTag('机组状态分析').a('yawPerformanceEvaluation',result.data.data3[4]);
							}
							if(result.data.overallMerit){
								if(result.data.overallMerit==="差"){
									dataModel.getDataByTag('机组状态分析').a('comprehensiveAssessment','assets/冀北/差.png');
								}else if(result.data.overallMerit==="中"){
									dataModel.getDataByTag('机组状态分析').a('comprehensiveAssessment','assets/冀北/中.png');
								}else if(result.data.overallMerit==="良"){
									dataModel.getDataByTag('机组状态分析').a('comprehensiveAssessment','assets/冀北/良.png');
								}else{
									dataModel.getDataByTag('机组状态分析').a('comprehensiveAssessment','assets/冀北/优.png');
								}

								
							}
						}
					}
				});
			}
			
			
        </script>
    </head>
    <body onload='setTimeout(init, 300)'>
    </body>
</html>
